// 封装ajax
const baseUrl = "http://xawn.f3322.net:10002";

function request(url, data, method, header) {
	uni.showLoading({
		title: "加载中...请稍后..."
	})
	const token = uni.getStorageSync("_token");
	let headerToken = null;
	if (token) {
		headerToken = {
			"Authori-zation": token
		};
	}
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + url,
			data,
			method: method || "GET",
			header: header || headerToken || {
				"Content-Type": "application/json"
			},
			success(res) {
				uni.hideLoading()
				resolve(res.data)
			},
			fail(e) {
				reject(e)
			},
			complete() {
				uni.hideLoading()
			}
		})
	})
}

export default request
